#pragma once

#include "CDXResource.h"
#ifdef __SWIG__
#include "D3D11_swig.h"
%include <typemaps.i>
%include "mui_typemap.i"
%apply SWIGTYPE& OUTPUT {D3D11_BUFFER_DESC& outDesc};
%apply SWIGTYPE& OUTPUT { UINT& outSzElem};
%apply SWIGTYPE& OUTPUT { UINT& outnElem};
%apply UINT* OUTPUT {UINT* outSzElem};
%apply UINT* OUTPUT {UINT* outnElem};
%apply SWIGTYPE** OUTPUT { ID3D11UnorderedAccessView** ppUnorderAccessView};
%apply SWIGTYPE** OUTPUT { ID3D11ShaderResourceView** ppShaderResourceView};
%apply SWIGTYPE** OUTPUT { ID3D11RenderTargetView** ppRenderTargetView};
%apply SWIGTYPE** OUTPUT { CDXBuffer** ppDstBuf};

#endif
class CDXBuffer : public CDXResource
{
private:
	ID3D11Buffer* m_pCPUAccessBuffer;
	HRESULT CreateCPUAccessBuffer();
protected:
	ID3D11Buffer* m_pBuffer;
	UINT m_szElem;
	UINT m_nElem;
protected:
	//override CDXResource
	virtual HRESULT ReleaseResources();
public:
	CDXBuffer(CDXDevice* pDevice);
	virtual ~CDXBuffer();
	virtual ID3D11Resource* GetResource() const;
	virtual HRESULT Create(D3D11_BUFFER_DESC* pDesc, DWORD szElem, DWORD nElem, D3D11_SUBRESOURCE_DATA* pInitData);

	virtual HRESULT Write(BYTE* data, unsigned long szData, unsigned long srcOffset, unsigned long dstOffset, BOOL bDiscard = FALSE);
	virtual HRESULT Read(BYTE* pData, unsigned long szData, unsigned long offset, BOOL bUpdate);
	virtual ID3D11Buffer* GetBuffer();
	virtual HRESULT OpenShareHandle(HANDLE hResource);
	virtual HRESULT GetDesc(D3D11_BUFFER_DESC& outDesc, UINT& outSzElem, UINT& outnElem);
	virtual HRESULT CloneTo(CDXBuffer** ppDstBuf);

	using CDXResource::GetShaderResourceView;
	using CDXResource::GetUnorderedAccessView;
	using CDXResource::GetRenderTargetView;
	virtual HRESULT GetShaderResourceView(DXGI_FORMAT fmt, ID3D11ShaderResourceView** ppShaderResourceView);
	virtual HRESULT GetUnorderedAccessView(DXGI_FORMAT fmt, UINT uavFlag, ID3D11UnorderedAccessView** ppUnorderAccessView);
	virtual HRESULT GetRenderTargetView(DXGI_FORMAT fmt, ID3D11RenderTargetView** ppRenderTargetView);
};

